import 'package:flutter/material.dart';
import 'package:flutter_soundmagus/page/eq/eq_controller.dart';
import 'package:flutter_soundmagus/widget/circular_slider.dart';
import 'package:flutter_soundmagus/widget/eq/eq.dart';
import 'package:flutter_soundmagus/widget/widget.dart';
import 'package:get/get.dart';

class EqQFreqItem extends GetView<EqController> {
  final bool isQ;
  final FocusNode? focusNode;
  const EqQFreqItem({Key? key, this.isQ = false, this.focusNode}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Obx(() => CircularSlider(
          size: 100,
          min: isQ ? kQMin : kFreqMin.toDouble(),
          max: isQ ? kQMax : kFreqMax.toDouble(),
          initialValue: isQ ? controller.q.value : controller.freq.value.toDouble(),
          onChange: ((p0) {
            if (isQ) {
              controller.updateQ(p0);
            } else {
              controller.updateFreq(p0.toInt());
            }
          }),
          onIncrease: () {
            if (isQ) {
              controller.editQ(true);
            } else {
              controller.editFreq(true);
            }
          },
          onDecrease: () {
            if (isQ) {
              controller.editQ(false);
            } else {
              controller.editFreq(false);
            }
          },
          decreaseOffset: Offset(0, 20),
          increaseOffset: Offset(0, 20),
          innerWidget: (v) => Align(
            alignment: Alignment.center,
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                Padding(
                  padding: const EdgeInsets.only(bottom: 8),
                  child: Text(
                    isQ ? 'Q:' : 'Freq:',
                    style: Theme.of(context).textTheme.bodyLarge,
                  ),
                ),
                TextField(
                  focusNode: focusNode,
                  controller: isQ ? controller.textEditingControllerQ : controller.textEditingControllerFreq,
                  onSubmitted: (v) {
                    if (isQ) {
                      controller.qChange();
                    } else {
                      controller.freqChange();
                    }
                  },
                  onEditingComplete: () {},
                  style: TextStyle(color: Colors.white),
                  keyboardType: isQ ? TextInputType.numberWithOptions(decimal: true) : TextInputType.number,
                  // inputFormatters: [
                  //   // FilteringTextInputFormatter.digitsOnly
                  // ], //只允许数字
                  textAlign: TextAlign.center,
                ),
              ],
            ),
          ),
        ));
  }
}
